package com.yifang.yibingproject.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifang.yibingproject.entity.SysAuthEntity;
import com.yifang.yibingproject.mapper.SysAuthMapper;
import com.yifang.yibingproject.service.SysAuthService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class SysAuthServiceImpl extends ServiceImpl<SysAuthMapper, SysAuthEntity> implements SysAuthService {

    /**
     * 根据权限ID获取权限集合
     * @param roleId
     * @return
     */
    @Override
    public List<SysAuthEntity> listAuthsByRoleId(Long roleId) {
        if(roleId==null || roleId < 0){
            return new ArrayList<>();
        }
        LambdaQueryWrapper<SysAuthEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysAuthEntity::getId,roleId);
        List<SysAuthEntity> list = list(lambdaQueryWrapper);
        return list;
    }


    /**
     * 获取所有的权限集合
     * @return
     */
    @Override
    public Set<Long> getAllAuthIdSet() {
        List<SysAuthEntity> list = list();
        Set<Long> ids = list.stream().map(SysAuthEntity::getId).collect(Collectors.toSet());
        return ids;
    }
}
